/*
 * Copyright (C) 2011-2013 Eric Lasota
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#ifndef __RDX_ZONEPOLICY_HPP__
#define __RDX_ZONEPOLICY_HPP__

#include "rdx_objectmanagement.hpp"

namespace RDX
{
	namespace Programmability
	{
		class String;
	};

	namespace IO
	{
		struct IFileSystem;
	};

	namespace Security
	{
		static const int MAX_ZONEPOLICY_PATH = 4000;

		struct Zone
		{
			Programmability::String *namespacePrefix;
			Bool preferTextOut;
			Bool canContainMethods;
			Zone **visibleZones;
		};

		class ZonePolicyPackageHost : public ObjectManagement::IPackageHost
		{
		public:
			struct ZoneInfo
			{
				LargeInt firstPackage;
				LargeInt numPackages;
			};

		private:

			ObjectManagement::CRef<const Programmability::String*> _packageNames;
			ObjectManagement::CRef<LargeInt> _packageZones;
			ObjectManagement::CRef<ZoneInfo> _zoneInfo;
			ObjectManagement::CRef<Zone*> _zones;

			ObjectManagement::CRef<Programmability::Type> _zoneArrayType;
			ObjectManagement::CRef<Programmability::ArrayOfType> _stringArrayType;

			LargeInt _numZones;
			ObjectManagement::IObjectManager *_objm;
			IO::IFileSystem *_fs;

			bool _forceTextRead;

		public:
			virtual ~ZonePolicyPackageHost();

			inline ZonePolicyPackageHost() { };
			ZonePolicyPackageHost(OperationContext *ctx, ObjectManagement::IObjectManager *objm, IO::IFileSystem *fs, bool forceTextFirst);

			virtual void LoadZones(OperationContext *ctx, Zone **zones);

			ObjectManagement::Domain DomainForSymbolName(ObjectManagement::IObjectManager *om, const Programmability::String *str, ObjectManagement::Domain domain = ObjectManagement::DOMAIN_Indeterminate);
			IO::IFileStream *StreamForDomain(ObjectManagement::IObjectManager *om, ObjectManagement::Domain domain, bool write, bool &isText);
			bool DomainsVisible(ObjectManagement::Domain sourceDomain, ObjectManagement::Domain destDomain);
			bool DomainCanContainMethods(ObjectManagement::Domain domain);
			void SetForceTextReadPreference(bool enable);
		};
	}
}

#endif

